package com.le.tester.javaThink.fifth.chapter13_FuncProgramming;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;

/**
 * createTime：2021/8/6 14:48
 * description：use list
 */
public class Closure8 {
    Supplier<List<Integer>> makeFun() {
        //在这个地方new了两个对象，地址也因此也不一样
        final List<Integer> ai = new ArrayList<>();
        ai.add(1);
        return () -> ai;
    }

    public static void main(String[] args) {
        Closure8 c7 = new Closure8();
        List<Integer> l1 = c7.makeFun().get();
        List<Integer> l2 = c7.makeFun().get();
        System.out.println(l1);
        System.out.println(l2);
        l1.add(42);
        l2.add(96);
        System.out.println(l1);
        System.out.println(l2);
    }
}
